import { ref } from 'vue'

import { getProductList } from '@/api/product'

const productListParams = ref<ProductListParamsType>({
  cate_id: null,
  type: 0,
  store_name: '',
  sales: '',
  page: 1,
  limit: 10,
})

const productList = ref<ProductInfoType[]>([])
const productCount = ref(0)
const isLoadingProductList = ref<boolean>(true)

function handleGetProductList() {
  isLoadingProductList.value = true
  getProductList(productListParams.value)
    .then(res => {
      productCount.value = res.count
      productList.value = res.list
    })
    .finally(() => {
      isLoadingProductList.value = false
    })
}

export {
  productCount,
  productListParams,
  productList,
  isLoadingProductList,
  handleGetProductList,
}
